﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace LabMS.Web.LabManage
{
    public partial class PreViewAward : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("HJXX");
            if (UserType == "student" || UserType == "teacher")
            {
                modifybtn.Visible = false;
                DeleteBtn.Visible = false;
            }
            if (Request.QueryString["ID"] != null)
            {
                if (!IsPostBack)
                {
                    int ID;
                    string strID = Request.QueryString["ID"].ToString();
                    if (int.TryParse(strID, out ID))
                    {

                        LabMS.BLL.AwardInfo award = new LabMS.BLL.AwardInfo();
                        LabMS.Model.AwardInfo awardinfo = new LabMS.Model.AwardInfo();
                        List<LabMS.Model.Dictionary> list = new List<LabMS.Model.Dictionary>();

                        IDHF.Value = ID.ToString();//存储ID值
                        //获取奖励信息 通过ID
                        awardinfo = award.GetModel(ID);

                        AwardNameLbl.Text = awardinfo.Award_Name;//获取奖励名
                        AwarderLbl.Text = awardinfo.Award_Winner;//获取获奖者名
                        AwardContentLbl.Text = awardinfo.Award_Content;//奖励内容
                        PresentationLbl.Text = awardinfo.Award_Presentation;//颁奖单位
                        AwardDateLbl.Text = string.Format("{0:d}", awardinfo.Award_Time);  //日期

                        //绑定奖励级别
                        list = DictionaryDropdownlist("114");
                        AwardLevelDDL.DataSource = list;
                        AwardLevelDDL.DataBind();
                        AwardLevelDDL.SelectedValue = awardinfo.Award_Level.ToString();

                        //绑定获奖类型
                        list = DictionaryDropdownlist("116");
                        AwardTypeDDL.DataSource = list;
                        AwardTypeDDL.DataBind();
                        AwardTypeDDL.SelectedValue = awardinfo.Award_Type.ToString();

                        //绑定实验室名
                        LabDropdownlist();
                        LabNameDDL.SelectedValue = awardinfo.Award_Lab.ToString();
                    }
                    else
                    {
                        ERRLbl.Text = "系统异常，ID值不合法！";
                        ERRLbl.Visible = true;
                        modifybtn.Visible = false;
                        DeleteBtn.Visible = false;
                    }
                }
            }
            else
            {
                ERRLbl.Text = "系统异常，ID值不合法！";
                ERRLbl.Visible = true;
                modifybtn.Visible = false;
                DeleteBtn.Visible = false;
            }
        }

        //绑定实验室名称 下拉列表框
        protected void LabDropdownlist()
        {
            LabMS.BLL.Lab lab = new LabMS.BLL.Lab();
            DataSet ds = new DataSet();

            ds = lab.GetAllList();
            LabNameDDL.DataSource = ds;
            LabNameDDL.DataBind();
        }

        //绑定数据字典 返回List
        protected List<LabMS.Model.Dictionary> DictionaryDropdownlist(string code)
        {
            string strwhere = "DClass='" + code + "'";
            LabMS.BLL.Dictionary dic = new LabMS.BLL.Dictionary();

            List<LabMS.Model.Dictionary> list = new List<LabMS.Model.Dictionary>();
            list = dic.GetModelList(strwhere);
            return list;
        }

        //删除
        protected void Delete_Click(object sender, EventArgs e)
        {
            LabMS.BLL.AwardInfo award = new LabMS.BLL.AwardInfo();
            try
            {
                int ID = int.Parse(IDHF.Value);
                award.Delete(ID);
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('删除成功!');refreshParent();wincolse();</script>");
            }
            catch
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script type='text/javascript'>alert('删除失败,请重新删除！');refreshParent();wincolse();</script>");
            }
        }
    }
}
